package com.titaniume.rqbbitmq.eight;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.titaniume.rqbbitmq.util.RabbitMqUtils;

/**
 * @program: rqbbitmq-hello
 * @description: 死信队列 消息生产者
 * @author: titaniume
 * @create: 2021-12-23 09:07
 */
public class Producter {

    private static final String NORMAL_EXCHANGE = "normal_exchange";
    private static final String NORMAL_QUEUE = "normal_queue";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //声明交换机
        channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);
        //死信消息设置TTL时间 单位是ms 10000ms = 10s
//        AMQP.BasicProperties properties = new AMQP.BasicProperties()
//                .builder()
//                .expiration("10000").build();
        channel.queueBind(NORMAL_QUEUE, NORMAL_EXCHANGE, "zhangsan");
        for (int i = 1; i <= 10; i++) {
            String message = "info" + i;
            channel.basicPublish(NORMAL_EXCHANGE, "zhangsan",null, message.getBytes("UTF-8"));
            System.out.println("生产者发出消息:" + message);
        }
    }
}